package com.example.myapplication.teenager;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.StationDetailsBean;
import com.google.gson.Gson;

import org.jetbrains.annotations.NotNull;
import org.w3c.dom.Text;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class StationDetailsActivity extends AppCompatActivity {

    private String dataBeanID;
    private TextView yizhan_introduce;
    private TextView yizhan_name;
    private ImageView yizhan_img;
    private Handler handler;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_station_details);
        Intent intent = getIntent();
        dataBeanID = intent.getStringExtra("DataBeanID");
        initview();
        sendbena();
    }

    private void sendbena() {
        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder()
                .url("http://124.93.196.45:10001//prod-api/api/youth-inn/talent-policy-area/"+dataBeanID)
                .addHeader("Authorization", TokenBean.token)
                .build();
        okHttpClient.newCall(request).enqueue(new Callback() {
            @Override
            public void onFailure(@NotNull Call call, @NotNull IOException e) {

            }

            @Override
            public void onResponse(@NotNull Call call, @NotNull Response response) throws IOException {
                String string = response.body().string();
                Gson gson = new Gson();
                StationDetailsBean stationDetailsBean = gson.fromJson(string, StationDetailsBean.class);
                handler.post(new Runnable() {
                    @Override
                    public void run() {
                        Glide.with(StationDetailsActivity.this).load(stationDetailsBean.getData().getImgUrl()).into(yizhan_img);
                        yizhan_name.setText(stationDetailsBean.getData().getName());
                        yizhan_introduce.setText(stationDetailsBean.getData().getIntroduce());
                    }
                });
            }
        });
    }

    private void initview() {
        yizhan_img = findViewById(R.id.yizhan_img);
        yizhan_name = findViewById(R.id.yizhan_name);
        yizhan_introduce = findViewById(R.id.yizhan_introduce);
        handler = new Handler();
    }
}